#include "stdio.h"
#include "stdlib.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "unistd.h"
#include "linux/input.h"

int main(int argc, char *argv[]) 
{
    struct input_event ev_in;
    int fd= -1, len = 0;

    if (argc != 2 ) {
        fprintf(stderr, "usage: %s <input-dev>\n", argv[1]);
        exit(-1);
    } 

    if ( (fd = open(argv[1], O_RDONLY)) < 0 ) {
        perror("open error");
        exit(-1);
    }

    len = sizeof(struct input_event);

    if ( read(fd, &ev_in, len) != len ) {
        perror("read error");
        exit(-1);
    }

    if ( EV_KEY == ev_in.type ) {
        switch (ev_in.value) {
            case 0:
                printf("code<%d>: 松开\n", ev_in.code);
                break;

            case 1:
                printf("code<%d>: 按下\n", ev_in.code);
                break;

            case 2:
                printf("code<%d>: 长按\n", ev_in.code);
                break;
        }
    }
}